package cn.ccydrools.service;

import cn.ccydrools.utils.ClickHouseUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class ClickHouseQueryServiceImpl implements QueryService {

    @Override
    public boolean queryEventCountByRangeTime(String sql, String uid,  String cid, String type, long startTime, long endTime, int counts) throws Exception {
        Connection connection = ClickHouseUtil.getClickHouseConnection();
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, uid);
        preparedStatement.setString(2, cid);
        preparedStatement.setString(3, type);
        preparedStatement.setLong(4, startTime);
        preparedStatement.setLong(5, endTime);
        int result = 0;
        ResultSet rs = preparedStatement.executeQuery();
        if(rs.next()) {
            result = rs.getInt("counts");
        }
        System.out.println(result);
        return result >= counts;
    }
}
